import { request, requestWithErrorHandling } from "./request";

/**
 * 获取AI聊天历史记录
 * @param {number} userId - 用户ID
 * @returns {Promise} 返回历史记录列表
 */
export function getAiHistory(userId) {
  return requestWithErrorHandling({
    url: "/ai_history",
    method: "get",
    params: { user_id: userId },
    errorMessage: "获取聊天历史失败",
  });
}

/**
 * 保存AI聊天记录
 * @param {Object} data - 聊天记录数据
 * @param {number} data.user_id - 用户ID
 * @param {string} data.ask - 用户提问
 * @param {string} data.reply - AI回复
 * @param {string} data.ai_type - AI类型 (gemini/coze)
 * @returns {Promise} 返回保存结果
 */
export function saveAiHistory(data) {
  return requestWithErrorHandling({
    url: "/ai_history",
    method: "post",
    data,
    errorMessage: "保存聊天记录失败",
  });
}

/**
 * 删除用户的所有AI聊天历史记录
 * @param {number} userId - 用户ID
 * @returns {Promise} 返回删除结果
 */
export function deleteAiHistory(userId) {
  return requestWithErrorHandling({
    url: `/ai_history/${userId}`,
    method: "delete",
    errorMessage: "删除聊天历史失败",
  });
}
